#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 810, M = 3000, INF = 0x3f3f3f3f;
int h[N], e[M], ne[M], w[M], idx;
int q[N], id[N];
bool st[N];
int dis[N];
int n, p, c;

int spfa(int start)
{
	memset(dis, 0x3f, sizeof(dis));
	dis[start] = 0;
	q[0] = start;
	st[start] = 1;
	int hh = 0, tt = 1;
	while (hh != tt) {
		int t = q[hh++];
		st[t] = 0;
		if (hh == N) {
			hh = 0;
		}
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[t] + w[i]) {
				dis[j] = dis[t] + w[i];
				if (!st[j]) {
					q[tt++] = j;
					if (tt == N) {
						tt = 0;
					}
					st[j] = 1;
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		int j = id[i];
		if (dis[j] == INF) {
			return INF;
		}
		res += dis[j];
	}
	return res;
}
void add(int a, int b, int u)
{
	w[idx] = u;
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx++;
}
int main()
{
	cin >> n >> p >> c;
	for (int i = 0; i < n; i++) {
		cin >> id[i];
	}
	memset(h, -1, sizeof(h));
	while (c--) {
		int a, b, z;
		cin >> a >> b >> z;
		add(a, b, z);
		add(b, a, z);
	}
	int res = INF;
	for (int i = 1; i <= p; i++) {
		res = min(res, spfa(i));
	}
	cout << res << endl;
	return 0;
}